//
// Created by Jisam on 23/10/2024 22:08.
// Solution of  template
#include <bits/stdc++.h>

#define int long long
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;
const int MAXN = 2e5 + 5;
int c[MAXN];

signed main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int>> ma(n + 1, vector<int>(n + 1, 0));
    for (int i = 1; i <= n; i++)
        cin >> c[i];
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= i; j++)
        {
            ma[i][j] = ma[i][j - 1]+ (c[i] != c[j])*(i - j);
        }
    }
    
    int ans = 0;
    for(auto x : ma){
        ans += *max_element(all(x));
    }
    cout << ans;
    return 0;
}